package com.heima.user.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.LoginDto;
import com.heima.model.user.pojo.ApUser;
import com.heima.user.service.ApUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

/**
 * <p>
 * APP用户信息表 前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/login")
public class ApUserController {

    private final ApUserService apUserService;

    /**
     * 构造注入bean
     * @param apUserService
     */
    @Autowired
    public ApUserController(ApUserService apUserService) {
        this.apUserService = apUserService;
    }

    /**
     * 登录验证
     * @param dto
     * @return
     */
    @PostMapping("/login_auth")
    public ResponseResult login(@RequestBody LoginDto dto) {
        return apUserService.login(dto);
    }

    /**
     * 获取验证码
     * @param phone
     */
    @GetMapping("/register/getCode/{phone}")
    public ResponseResult getCode(@PathVariable("phone") String phone) {
        return apUserService.getCode(phone);
    }

    /**
     * 验证验证码
     * @return
     */
    @GetMapping("/register/verifyCode")
    public ResponseResult verifyCode(@PathParam("phone")String phone,@PathParam("code")String code){
        return apUserService.verifyCode(phone, code);
    }

    /**
     * 用户注册
     * @param user
     * @return
     */
    @PutMapping("/register/usrReg")
    public ResponseResult usrReg(@RequestBody ApUser user) {
        return apUserService.usrReg(user);
    }

}




